package com.yuanfengerp.goodsInfoManage.servicer.impl;

import com.yuanfengerp.goodsInfoManage.dao.IProductDao;
import com.yuanfengerp.goodsInfoManage.model.ProductManagement;
import com.yuanfengerp.goodsInfoManage.servicer.IProductService;
import com.yuanfengerp.publicUtil.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Map;

@Service
public class IProductServiceImpl implements IProductService {
    @Autowired
    private IProductDao productDao;
    @Override
    public Result<ArrayList> selectAllProduct( Map<String ,Object> params ) {
        ArrayList<ProductManagement> productManagements = productDao.selectProduct(params);
        if (productManagements.size()>0) {
            return Result.success(productManagements);
        }else {
            return Result.failure(400,"当前数据库中没有相关数据");
        }
    }

    @Override
    public Result<ProductManagement> insertProduct(ProductManagement productManagement) {
        int i = productDao.insertProduct(productManagement);
        if (i>0){
            return Result.success(productManagement);
        }else{
            return Result.failure(400,"新增数据失败");
        }
    }

    @Override
    public Result<ProductManagement> selectProductById(String productManagementId) {
        ProductManagement productManagement = productDao.selectProductById(productManagementId);
        if ( productManagement != null){
            return Result.success(productManagement);
        }else{
            return Result.failure(400,"很抱歉,查询失败");
        }
    }
    @Override
    public Result<ProductManagement> updateProduct(ProductManagement productManagement) {
        int i = productDao.updateProductById(productManagement);
        if (i>0){
            return Result.success(productManagement);
        }else{
            return Result.failure(400,"很抱歉,修改失败");
        }
    }
    @Override
    public Result<ProductManagement> selectProductByName(String productManagementName) {
        if (productManagementName!=null){
            return Result.success(productDao.selectProductByName(productManagementName));
        }else {
            return Result.failure(400,"很抱歉,查询失败");
        }
    }
}
